package main

import (
	"log"
	"net/http"
	"net/http/cgi"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		handler := new(cgi.Handler)
		handler.Path = "D:\\goenv\\go\\bin\\go.exe"
		script := "C:\\go_api_study\\net\\http\\cgi\\src\\cgi-script\\" + r.URL.Path
		log.Println(handler.Path)
		handler.Dir = "C:\\go_api_study\\net\\http\\cgi\\src\\cgi-script\\"
		args := []string{"run", script}
		handler.Args = append(handler.Args, args...)
		handler.Env = append(handler.Env, "GOPATH=C:\\go_api_study\\net\\http\\cgi")
		handler.Env = append(handler.Env, "GOROOT=D:\\goenv\\go")
		log.Println(handler.Args)

		handler.ServeHTTP(w, r)
	})

	log.Fatal(http.ListenAndServe(":8989", nil))
}
